package app.server.project.main.service.service.lv;

import app.server.project.core.http.CMSLstResp;
import app.server.project.main.service.db.dao.cfg.LvCfgDao;
import app.server.project.main.service.db.entity.cfg.LvCfgEntity;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class LvCfgService {
    private LvCfgDao lvCfgDao;

    public CMSLstResp getAllCfg() {
        var cfg = this.lvCfgDao.getAll();
        return CMSLstResp.of(cfg, cfg.size());
    }

    public void save(LvCfgEntity lvCfgEntity) {
        this.lvCfgDao.removeById(lvCfgEntity.getLv());
        this.lvCfgDao.save(lvCfgEntity);
        this.lvCfgDao.init();
    }

    public void del(LvCfgEntity lvCfgEntity) {
        this.lvCfgDao.removeById(lvCfgEntity.getLv());
        this.lvCfgDao.init();
    }
}
